/*
 * BraveDictCreatorView.java
 */

package com.braveo.dict.tools;

import com.braveo.dict.business.CreatorApplication;
import com.braveo.dict.business.CreatorConfig;
import com.braveo.dict.db.BraveDictEntryDao;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.lang.String;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.ListModel;

/**
 * The application's main frame.
 */
public class BraveDictCreatorView extends FrameView {

    public BraveDictCreatorView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = BraveDictCreatorApp.getApplication().getMainFrame();
            aboutBox = new BraveDictCreatorAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        BraveDictCreatorApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        btnLoad = new javax.swing.JButton();
        btnSaveAs = new javax.swing.JButton();
        btnAddNew = new javax.swing.JButton();
        txtNewKey = new javax.swing.JTextField();
        btnUpdate = new javax.swing.JButton();
        cbLowerCase = new javax.swing.JCheckBox();
        btnHyper = new javax.swing.JButton();
        btnTrimHead = new javax.swing.JButton();
        btnOtherTag = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstKeys = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        taExplain = new javax.swing.JTextArea();
        btnCreateSQL = new javax.swing.JButton();
        btnPaste = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.braveo.dict.tools.BraveDictCreatorApp.class).getContext().getResourceMap(BraveDictCreatorView.class);
        btnLoad.setText(resourceMap.getString("btnLoad.text")); // NOI18N
        btnLoad.setName("btnLoad"); // NOI18N
        btnLoad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoadActionPerformed(evt);
            }
        });

        btnSaveAs.setText(resourceMap.getString("btnSaveAs.text")); // NOI18N
        btnSaveAs.setActionCommand(resourceMap.getString("btnSaveAs.actionCommand")); // NOI18N
        btnSaveAs.setName("btnSaveAs"); // NOI18N

        btnAddNew.setText(resourceMap.getString("btnAddNew.text")); // NOI18N
        btnAddNew.setName("btnAddNew"); // NOI18N
        btnAddNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddNewActionPerformed(evt);
            }
        });

        txtNewKey.setText(resourceMap.getString("txtNewKey.text")); // NOI18N
        txtNewKey.setName("txtNewKey"); // NOI18N

        btnUpdate.setText(resourceMap.getString("btnUpdate.text")); // NOI18N
        btnUpdate.setName("btnUpdate"); // NOI18N
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        cbLowerCase.setText(resourceMap.getString("cbLowerCase.text")); // NOI18N
        cbLowerCase.setName("cbLowerCase"); // NOI18N

        btnHyper.setText(resourceMap.getString("btnHyper.text")); // NOI18N
        btnHyper.setName("btnHyper"); // NOI18N
        btnHyper.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHyperActionPerformed(evt);
            }
        });

        btnTrimHead.setText(resourceMap.getString("btnTrimHead.text")); // NOI18N
        btnTrimHead.setName("btnTrimHead"); // NOI18N
        btnTrimHead.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrimHeadActionPerformed(evt);
            }
        });

        btnOtherTag.setText(resourceMap.getString("btnOtherTag.text")); // NOI18N
        btnOtherTag.setName("btnOtherTag"); // NOI18N
        btnOtherTag.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOtherTagActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnLoad)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSaveAs)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUpdate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnHyper)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnTrimHead)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnOtherTag))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnAddNew)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNewKey, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cbLowerCase)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLoad)
                    .addComponent(btnSaveAs)
                    .addComponent(btnUpdate)
                    .addComponent(btnHyper)
                    .addComponent(btnTrimHead)
                    .addComponent(btnOtherTag))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAddNew)
                    .addComponent(txtNewKey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbLowerCase))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        lstKeys.setName("lstKeys"); // NOI18N
        lstKeys.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstKeysValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(lstKeys);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        taExplain.setColumns(20);
        taExplain.setLineWrap(true);
        taExplain.setRows(5);
        taExplain.setName("taExplain"); // NOI18N
        jScrollPane2.setViewportView(taExplain);

        btnCreateSQL.setText(resourceMap.getString("btnCreateSQL.text")); // NOI18N
        btnCreateSQL.setName("btnCreateSQL"); // NOI18N

        btnPaste.setText(resourceMap.getString("btnPaste.text")); // NOI18N
        btnPaste.setName("btnPaste"); // NOI18N
        btnPaste.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPasteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnCreateSQL)
                            .addComponent(btnPaste)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(btnCreateSQL)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPaste)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE))
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(com.braveo.dict.tools.BraveDictCreatorApp.class).getContext().getActionMap(BraveDictCreatorView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 731, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 556, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed
        CreatorConfig cc = creatorApp.getConfig();
        JFileChooser jfc = new JFileChooser(cc.getDbDir());
        if(jfc.showOpenDialog(getFrame()) != JFileChooser.APPROVE_OPTION){
            return;
        }

        cc.setDbDir(jfc.getCurrentDirectory().getAbsolutePath());
        creatorApp.setConfig(cc);
        File file = jfc.getSelectedFile();
        dao = creatorApp.getDaoManager().getDao(file);

        List<String> xl = dao.getDictKeys();
        String[] xs = new String[xl.size()];
        xl.toArray(xs);
        lstKeys.setListData(xs);
    }//GEN-LAST:event_btnLoadActionPerformed

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        if(dao == null){
            JOptionPane.showMessageDialog(getFrame(), "Load data first, please");
            return;
        }

        String key = (String)lstKeys.getSelectedValue();
        if(key == null){
            JOptionPane.showMessageDialog(getFrame(), "Select a word first, please");
            return;
        }

        String expl = taExplain.getText();

        dao.updateDictEntry(key, expl);
        JOptionPane.showMessageDialog(getFrame(), "Update word OK");

    }//GEN-LAST:event_btnUpdateActionPerformed

    private void btnAddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddNewActionPerformed
        
        if (dao == null) {
            JOptionPane.showMessageDialog(getFrame(), "Load data first, please");
            return;
        }

        ListModel lm = lstKeys.getModel();

        String word = txtNewKey.getText().trim();
        if(cbLowerCase.isSelected()){
            word = word.toLowerCase();
        }
        if(word.length() == 0){
            return;
        }
        for(int k=0; k<lm.getSize(); ++k){
            String v = (String)lm.getElementAt(k);
            if(v.equals(word)){
                JOptionPane.showMessageDialog(getFrame(), "Duplicated word");
                return;
            }
        }

        dao.addDictEntry(word, "");

        List<String> xl = dao.getDictKeys();
        String[] xs = new String[xl.size()];
        xl.toArray(xs);
        lstKeys.setListData(xs);

        lm = lstKeys.getModel();
        for(int k=0; k<lm.getSize(); ++k){
            String v = (String)lm.getElementAt(k);
            if(v.equals(word)){
                lstKeys.setSelectedIndex(k);
                break;
            }
        }

        JOptionPane.showMessageDialog(getFrame(), "New word added : " + word);
        
    }//GEN-LAST:event_btnAddNewActionPerformed

    private void lstKeysValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstKeysValueChanged
        String word = (String)lstKeys.getSelectedValue();
        String expl = dao.getExplain(word);
        taExplain.setText(expl);
    }//GEN-LAST:event_lstKeysValueChanged

    private void btnHyperActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHyperActionPerformed
        String expl = taExplain.getText();

        //remove the returns
        String [] xe = expl.split("\r|\n");
        StringBuilder sb = new StringBuilder();
        for(String s : xe){
            sb.append(s);
            sb.append(" ");
        }
        expl = sb.toString();

        //Pattern p_return = Pattern.compile("[\n\r]+", Pattern.MULTILINE);
        Pattern p_br = Pattern.compile("<br\\s*>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
        Pattern p_nbsp = Pattern.compile("&nbsp;", Pattern.CASE_INSENSITIVE);
        Pattern p_hyper = Pattern.compile("<a [^>]*>([^<>]+)</a>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);


        Matcher m = null;

        /*p_return.matcher(expl);
        m.replaceAll(" "); */

        m = p_br.matcher(expl);
        expl = m.replaceAll("\n");

        m = p_nbsp.matcher(expl);
        expl = m.replaceAll(" ");

        m = p_hyper.matcher(expl);
        expl = m.replaceAll("[$1]");

        taExplain.setText(expl);
    }//GEN-LAST:event_btnHyperActionPerformed

    private void btnTrimHeadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTrimHeadActionPerformed
        String expl = taExplain.getText();
        String[] xe = expl.split("\r|\n");
        StringBuilder sb = new StringBuilder();
        for(String s : xe){
            sb.append(s.trim()).append("\n");
        }
        taExplain.setText(sb.toString());
    }//GEN-LAST:event_btnTrimHeadActionPerformed

    private void btnOtherTagActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOtherTagActionPerformed
        String expl = taExplain.getText();

        Pattern p = Pattern.compile("<[^>]+>");
        Matcher m = p.matcher(expl);
        expl = m.replaceAll(" ");
        taExplain.setText(expl);
    }//GEN-LAST:event_btnOtherTagActionPerformed

    private void btnPasteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPasteActionPerformed
        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
        try{
            DataFlavor df = new DataFlavor("text/html;class=java.lang.String;charset=Unicode");
            String s = (String)cb.getData(df);
            if (s != null) {
                taExplain.setText(s);
            }
        }catch(Exception e){
            
        }
    }//GEN-LAST:event_btnPasteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddNew;
    private javax.swing.JButton btnCreateSQL;
    private javax.swing.JButton btnHyper;
    private javax.swing.JButton btnLoad;
    private javax.swing.JButton btnOtherTag;
    private javax.swing.JButton btnPaste;
    private javax.swing.JButton btnSaveAs;
    private javax.swing.JButton btnTrimHead;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JCheckBox cbLowerCase;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList lstKeys;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextArea taExplain;
    private javax.swing.JTextField txtNewKey;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private final CreatorApplication creatorApp = CreatorApplication.getApplication();
    private BraveDictEntryDao dao;

    private JDialog aboutBox;
}
